package com.bj58.mis.apm.server.kylin.model;

import com.bj58.mis.apm.server.kylin.util.JsonUtil;

import java.util.*;

public class CubeDesc {
    private String uuid;
    private Long last_modified;
    private String name;
    private Boolean is_draft;
    private String model_name;
    private String description;
    private String null_string;
    private List<Map<String, Object>> dimensions; //维度
    private List<Map<String, Object>> measures; //测量值
    private List<Map<String, Object>> dictionaries; //
    private Map<String, Object> rowkey; //共享rowkey配置
    private Map<String, Object> hbase_mapping; //column_familys
    /**
     * 聚合组：
     * 包括
     * includes维度、
     * Mandatory Dimensions强制维度、
     * Hierarchy Dimensions层级维度、
     * Joint Dimensions联合维度、
     * 衍生维度
     */
    private List<Map<String, Object>> aggregation_groups;
    private String signature;
    private List<Map<String, Object>> notify_list;
    private List<String> status_need_notify;
    private int parent_forward;
    private List<Long> cuboid_black_list;

    private Date d_last_modified;
    private String dimension;
    private String measure;
    private String aggregationGroups;
    private String cuboidBlackList;

    private Project project;
    private long full_mark = 0L;
    private List<RowKeyDesc> rowKeyDescs = new ArrayList<>();
    private Map<String, RowKeyDesc> columnMap = new HashMap<>();

    private CuboidScheduler cuboidScheduler;

    public CubeDesc deal(){
        if(this.dimensions != null && this.dimensions.size() > 0){
            this.dimension = JsonUtil.toString(this.dimensions);
        }
        if(this.measures != null && this.measures.size() > 0){
            this.measure = JsonUtil.toString(this.measures);
        }
        if(this.aggregation_groups != null && this.aggregation_groups.size() > 0){
            this.aggregationGroups = JsonUtil.toString(this.aggregation_groups);
        }
        d_last_modified = new Date(this.last_modified);

        if(this.cuboid_black_list != null && this.cuboid_black_list.size() > 0){
            this.cuboidBlackList = JsonUtil.toString(this.cuboid_black_list);
        }
        Object rows = rowkey.get("rowkey_columns");
        if(rows != null){
            List<Map<String, Object>> list = (List<Map<String, Object>>)rows;

            for(int i = 0; i < list.size(); i++){
                RowKeyDesc rk = new RowKeyDesc(list.get(i));
                rk.setIndexNumber(i + 1);
                rk.setBitIndex(list.size() - rk.getIndexNumber());
                rk.setCubedesc_id(this.uuid);
                rowKeyDescs.add(rk);
                columnMap.put(rk.getColumnName(), rk);
                full_mark |= 1L << i;
            }
        }

        return this;
    }

    public int getColumnBitIndex(String columnName){
        return columnMap.get(columnName).getBitIndex();
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public Long getLast_modified() {
        return last_modified;
    }

    public void setLast_modified(Long last_modified) {
        this.last_modified = last_modified;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getIs_draft() {
        return is_draft;
    }

    public void setIs_draft(Boolean is_draft) {
        this.is_draft = is_draft;
    }

    public String getModel_name() {
        return model_name;
    }

    public void setModel_name(String model_name) {
        this.model_name = model_name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getNull_string() {
        return null_string;
    }

    public void setNull_string(String null_string) {
        this.null_string = null_string;
    }

    public List<Map<String, Object>> getDimensions() {
        return dimensions;
    }

    public void setDimensions(List<Map<String, Object>> dimensions) {
        this.dimensions = dimensions;
    }

    public List<Map<String, Object>> getMeasures() {
        return measures;
    }

    public void setMeasures(List<Map<String, Object>> measures) {
        this.measures = measures;
    }

    public List<Map<String, Object>> getDictionaries() {
        return dictionaries;
    }

    public void setDictionaries(List<Map<String, Object>> dictionaries) {
        this.dictionaries = dictionaries;
    }

    public Map<String, Object> getRowkey() {
        return rowkey;
    }

    public void setRowkey(Map<String, Object> rowkey) {
        this.rowkey = rowkey;
    }

    public Map<String, Object> getHbase_mapping() {
        return hbase_mapping;
    }

    public void setHbase_mapping(Map<String, Object> hbase_mapping) {
        this.hbase_mapping = hbase_mapping;
    }

    public List<Map<String, Object>> getAggregation_groups() {
        return aggregation_groups;
    }

    public void setAggregation_groups(List<Map<String, Object>> aggregation_groups) {
        this.aggregation_groups = aggregation_groups;
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }

    public List<Map<String, Object>> getNotify_list() {
        return notify_list;
    }

    public void setNotify_list(List<Map<String, Object>> notify_list) {
        this.notify_list = notify_list;
    }

    public List<String> getStatus_need_notify() {
        return status_need_notify;
    }

    public void setStatus_need_notify(List<String> status_need_notify) {
        this.status_need_notify = status_need_notify;
    }

    public String getAggregationGroups() {
        return aggregationGroups;
    }

    public void setAggregationGroups(String aggregationGroups) {
        this.aggregationGroups = aggregationGroups;
    }

    public String getDimension() {
        return dimension;
    }

    public void setDimension(String dimension) {
        this.dimension = dimension;
    }

    public String getMeasure() {
        return measure;
    }

    public void setMeasure(String measure) {
        this.measure = measure;
    }

    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    public Date getD_last_modified() {
        return d_last_modified;
    }

    public void setD_last_modified(Date d_last_modified) {
        this.d_last_modified = d_last_modified;
    }

    public long getFull_mark() {
        return full_mark;
    }

    public void setFull_mark(long full_mark) {
        this.full_mark = full_mark;
    }

    public List<RowKeyDesc> getRowKeyDescs() {
        return rowKeyDescs;
    }

    public void setRowKeyDescs(List<RowKeyDesc> rowKeyDescs) {
        this.rowKeyDescs = rowKeyDescs;
    }

    public int getParent_forward() {
        return parent_forward;
    }

    public void setParent_forward(int parent_forward) {
        this.parent_forward = parent_forward;
    }

    public List<Long> getCuboid_black_list() {
        return cuboid_black_list;
    }

    public void setCuboid_black_list(List<Long> cuboid_black_list) {
        this.cuboid_black_list = cuboid_black_list;
    }

    public String getCuboidBlackList() {
        return cuboidBlackList;
    }

    public void setCuboidBlackList(String cuboidBlackList) {
        this.cuboidBlackList = cuboidBlackList;
    }

    public CuboidScheduler getCuboidScheduler() {
        return cuboidScheduler;
    }

    public void setCuboidScheduler(CuboidScheduler cuboidScheduler) {
        this.cuboidScheduler = cuboidScheduler;
    }
}
